package com.ruoyi.quartz.task;

import com.ruoyi.system.domain.MaterialInventory;
import com.ruoyi.system.response.MaterialInventoryList;
import com.ruoyi.system.service.IMaterialInventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

@Component("materialInventoryTask")

public class MaterialInventoryTask {
    @Autowired
    private IMaterialInventoryService materialInventoryService;

    public void clearInventoryData() {
        MaterialInventory materialInventory = new MaterialInventory();
        materialInventory.setEntryNum(0);
        List<MaterialInventoryList> materialInventories = materialInventoryService.selectMaterialInventoryList(materialInventory);
        if (CollectionUtils.isEmpty(materialInventories)) {
            return;
        }
        List<Long> ids = materialInventories.stream().map(MaterialInventory::getId).collect(Collectors.toList());
        materialInventoryService.removeBatchByIds(ids);
    }
}
